package work.rhee.AttendManager;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class AttendDBHelper extends SQLiteOpenHelper {

	private static final String DB_NAME = "attendDB.db" ;
	private static final int DB_VERSION = 1 ;

	public AttendDBHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase attendDB) {
		// TODO Auto-generated method stub
		StringBuilder attendTBLSQL = new StringBuilder() ;
		StringBuilder memberTBLSQL = new StringBuilder() ;
		StringBuilder eventTBLSQL = new StringBuilder() ;
		
		memberTBLSQL.append("CREATE TABLE ")
//		memberTBLSQL.append("CREATE TABLE if not exists ")
			.append(AttendDB.MemberTable.TABLE_NAME)
			.append(" ( ")
			.append(AttendDB.MemberTable._ID)
			.append(" INTEGER PRIMARY KEY AUTOINCREMENT , ")
				.append(AttendDB.MemberTable.GROUPNAME1)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.GROUPNAME2)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.GROUPNAME3)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.POSITION)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.NAME)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.HANDPHONE)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.TELEPHONE)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.EADDRESS)
				.append(" TEXT, ")
				.append(AttendDB.MemberTable.AUTOATTEND)
				.append(" INTEGER, ")
				.append(AttendDB.MemberTable.MEMO)
				.append(" TEXT ")
			.append(" ); ") ;
		
		attendTBLSQL.append("CREATE TABLE ")
//		attendTBLSQL.append("CREATE TABLE if not exists ")
		.append(AttendDB.AttendTable.TABLE_NAME)
		.append(" ( ")
		.append(AttendDB.AttendTable._ID)
		.append(" INTEGER PRIMARY KEY AUTOINCREMENT , ")
			.append(AttendDB.AttendTable.MEMBER_ID)
			.append(" INTEGER, ")
			.append(AttendDB.AttendTable.EVENT_ID)
			.append(" INTEGER, ")
			.append(AttendDB.AttendTable.ATTEND_DATE)
			.append(" TEXT, ")
			.append(AttendDB.AttendTable.ATTEND_STIME)
			.append(" TEXT, ")
			.append(AttendDB.AttendTable.ATTEND_ETIME)
			.append(" TEXT, ")
			.append(AttendDB.AttendTable.ATTEND_LATE_YES)
			.append(" TEXT, ")
			.append(AttendDB.AttendTable.ATTEND_MEMO)
			.append(" TEXT ")
		.append(" ); ") ;
		

		eventTBLSQL.append("CREATE TABLE ")
//		eventTBLSQL.append("CREATE TABLE if not exists ")
		.append(AttendDB.EventTable.TABLE_NAME)
		.append(" ( ")
		.append(AttendDB.EventTable._ID)
		.append(" INTEGER PRIMARY KEY AUTOINCREMENT , ")
			.append(AttendDB.EventTable.EVENT_NAME)
			.append(" TEXT, ")
			.append(AttendDB.EventTable.EVENT_DATE)
			.append(" TEXT, ")
			.append(AttendDB.EventTable.EVENT_STIME)
			.append(" TEXT, ")
			.append(AttendDB.EventTable.EVENT_ETIME)
			.append(" TEXT, ")
			.append(AttendDB.EventTable.EVENT_MEMO)
			.append(" TEXT ")
		.append(" ); ") ;
		
		attendDB.execSQL(memberTBLSQL.toString()) ;
		attendDB.execSQL(attendTBLSQL.toString()) ;
		attendDB.execSQL(eventTBLSQL.toString()) ;
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		super.onOpen(db);
	}

	
	
}

